package com.kingbook.api;

import com.kingbook.common.utils.DateUtils;
import com.kingbook.core.generator.Generator;
import com.kingbook.starter.BootApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import javax.sql.DataSource;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = BootApplication.class)
public class Initialization {

    @Resource
    private DataSource dataSource;

    private boolean overWrite = true;

    private String author = "Bucky";

    private String time = DateUtils.getDateTime();

    private String version = "1.0";

    private String root = "D:/kingbook/kingbook-server";

    private String schemaConfig = root + "/kingbook-services/src/main/resources/schemaConfig.xml";

    private String sqlFileTarget = root + "/kingbook-services/src/main/resources/sql";

    private String entityTarget = root + "/kingbook-services/src/main/java";

    private String serviceTarget = root + "/kingbook-services/src/main/java";

    private String restTarget = root + "/kingbook-api/src/main/java";

    private String entityPackage = "com.kingbook.entity";

    private String servicePackage = "com.kingbook.services";

    private String restPackage = "com.kingbook.api.rest";

    /**
     * 用于项目开始生成 sql.xml、entity、service、rest
     */
    @Test
    public void generator() throws Exception {
        Generator gen = new Generator();
        gen.setClassAnnotation(author, time, version);
        gen.setDataSourceAndSchema(dataSource, schemaConfig, overWrite);
        gen.setSqlFilePath(sqlFileTarget);
        gen.setEntityPath(entityTarget, entityPackage);
        gen.setServicePath(serviceTarget, servicePackage);
//        gen.setRestPath(restTarget, restPackage);
        gen.run();
    }


}
